package com.xjl.javacore.code.ioexample.udp;


import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**  DatagramSocket  先打包再发送
 * @author xiaojinlu1990@163.com
 * @date 2020/1/20 19:18
 */
public class udpExample {
    public static void main(String[] args) throws Exception {
//        1 创建UDP服务
        DatagramSocket datagramSocket = new DatagramSocket();

        InetAddress inetAddress = InetAddress.getLocalHost();
        int port = 12321;
        String message = "client";
        DatagramPacket packet =new DatagramPacket(message.getBytes() ,message.getBytes().length,inetAddress,port);
        //2发送资源
        datagramSocket.send(packet);
        //释放服务
        datagramSocket.close();
    }
}
